package com.hx.er.common.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.hx.er.bean.base.UserBean;
import com.hx.er.common.system.Constants;
import com.hx.er.common.system.ErSessions;

public class ErSessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		// 获取session
		HttpSession session = event.getSession();

		// 保存session
		ErSessions.add(session.getId(), session);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		// 获取session
		HttpSession session = event.getSession();
		UserBean userInfo = (UserBean) session.getAttribute(Constants.SESSION_USER_INFO);
		
		// 移除session
		ErSessions.remove(session.getId(), userInfo == null ? null : userInfo.getUserId());
	}
}
